package org.gvp.generator.core.writer.impl;

import org.gvp.generator.constant.ImportConstant;
import org.gvp.generator.core.writer.AbstractFileWriter;
import org.gvp.generator.props.CreateProps;
import org.gvp.generator.props.ProjectProps;
import org.gvp.generator.table.TableInfo;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * mp 映射接口文件写入类
 */
public class MapperFileWriter extends AbstractFileWriter {
    @Override
    public void execute(TableInfo tableInfo, ProjectProps project) {
        String upName = tableInfo.getUpperName();
        String classDefine = """
                /**
                * %s mp映射接口
                */
                @Mapper
                public interface %sMapper extends BaseMapper<%s> {
                """.formatted(tableInfo.getRemark(),upName,upName);

        channel.writeNewline(project.getBasePackageImport() + project.getMapperPackage() + ";");
        channel.writeEmptyLine();
        channel.writeNewline(ImportConstant.MYBATIS_PLUS_MAPPER);
        channel.writeNewline(project.getEntityImport());
        channel.writeNewline(classDefine);
        channel.writeNewline("}");
    }

    @Override
    public boolean isWriterFile(CreateProps create) {
        return create.isCreateMapper();
    }

    @Override
    public Path getFilePath(String basePath, ProjectProps project, String fileName) {
        return Paths.get(basePath,project.getMapperPackage(),fileName + "Mapper.java");
    }
}
